<?php
/**
 * Edit / add a bookmark
 *
 * @package Bookmarks
 */
$golf_course_id = get_input('golf_course_id');

$gold_tee_name = "black";
$blue_tee_name = "blue";
$white_tee_name = "white";
$red_tee_name = "red";
if($golf_course_id) {
	$golf_course = elgg_get_golf_course(array('golf_course_id' => $golf_course_id));
	$golf_course = $golf_course[0];
	
	$course_name = $golf_course -> course_name;
	$par_total = $golf_course -> par_total;
	
	$gold_tee_name = $golf_course -> gold_tee_name;
	$gold_course_rating = $golf_course -> gold_course_rating;
	$gold_course_slope = $golf_course -> gold_course_slope;
	$gold_total = $golf_course -> gold_total;
	
	$blue_tee_name = $golf_course -> blue_tee_name;
	$blue_course_rating = $golf_course -> blue_course_rating;
	$blue_course_slope = $golf_course -> blue_course_slope;
	$blue_total = $golf_course -> blue_total;
	
	$white_tee_name = $golf_course -> white_tee_name;
	$white_course_rating = $golf_course -> white_course_rating;
	$white_course_slope = $golf_course -> white_course_slope;
	$white_total = $golf_course -> white_total;
	
	$red_tee_name = $golf_course -> red_tee_name;
	$red_course_rating = $golf_course -> red_course_rating;
	$red_course_slope = $golf_course -> red_course_slope;
	$red_total = $golf_course -> red_total;
}

?>
<div class="elgg-add-score">
<div id="__course_form">
	<input type="hidden" name="golf_course_id" id="__golf_course_id" value="<?php echo $golf_course->golf_course_id;?>">
	<div style="overflow: hidden;">
		<span style="float: left; display: inline-block; width: 70%;">
		<label><?php echo elgg_echo('golfcourse:form:name'); ?></label><br>
		<?php echo elgg_view('input/text', array(
			'name' => "course_name",
			'id' => "__course_name",
			'value' => "$course_name",
		)); ?>
		</span>
		<span style="float: right; display: inline-block; width: 25%;">
		<label><?php echo elgg_echo('golfcourse:form:partotal'); ?></label><br>
		<?php echo elgg_view('input/text', array(
			'name' => "par_total",
			'id' => "__par_total",
			'value' => "$par_total",
		)); ?>
		</span>
	</div>
	<div style="margin-top: 5px;">
	<table>
	<thead>
		<tr>
			<th></th>
			<th><?php echo elgg_echo('golfcourse:form:course_rating'); ?></th>
			<th><?php echo elgg_echo('golfcourse:form:course_slope'); ?></th>
			<th><?php echo elgg_echo('golfcourse:form:distance_total'); ?></th>
		</tr>
	</thead>
	<tbody>
		<tr style="margin-top: 5px;" id="__tee_gold">
			<td>
				<div id="__tee_color" class="elgg-golfscore-icon-tee-<?php echo $gold_tee_name?>">&nbsp;</div>
				<label><?php echo elgg_echo('golfcourse:form:tee1'); ?></label>
				<?php echo elgg_view('input/dropdown', array(
					'class' => 'golfcourse-tee',
					'name' => 'gold_tee_name', 
					'id' => '__tee_name',
					'value' => $gold_tee_name,
					'onchange' => "onChangeTee('__tee_gold');",
					'options_values' => array(
						'gold' => elgg_echo('golfscore:tee:gold'),
						'black' => elgg_echo('golfscore:tee:black'),
						'blue' => elgg_echo('golfscore:tee:blue'),
						'white' => elgg_echo('golfscore:tee:white'),
						'red' => elgg_echo('golfscore:tee:red'),
					)
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-rating",
					'title' => elgg_echo('golfcourse:form:course_rating'),
					'placeholder' => elgg_echo('golfcourse:form:course_rating'),
					'name' => "gold_course_rating",
					'id' => "__course_rating",
					'value' => "$gold_course_rating",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-slope",
					'title' => elgg_echo('golfcourse:form:course_slope'),
					'placeholder' => elgg_echo('golfcourse:form:course_slope'),
					'name' => "gold_course_slope",
					'id' => "__course_slope",
					'value' => "$gold_course_slope",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-distance",
					'title' => elgg_echo('golfcourse:form:distance_total'),
					'placeholder' => elgg_echo('golfcourse:form:distance_total'),
					'name' => "gold_total",
					'id' => "__total",
					'value' => "$gold_total",
				)); ?>
			</td>
		</tr>
		<tr style="margin-top: 5px;" id="__tee_blue">
			<td>
				<div id="__tee_color" class="elgg-golfscore-icon-tee-<?php echo $blue_tee_name?>">&nbsp;</div>
				<label><?php echo elgg_echo('golfcourse:form:tee2'); ?></label>
				<?php echo elgg_view('input/dropdown', array(
					'class' => 'golfcourse-tee',
					'name' => 'blue_tee_name', 
					'id' => '__tee_name',
					'value' => $blue_tee_name,
					'options_values' => array(
						'gold' => elgg_echo('golfscore:tee:gold'),
						'black' => elgg_echo('golfscore:tee:black'),
						'blue' => elgg_echo('golfscore:tee:blue'),
						'white' => elgg_echo('golfscore:tee:white'),
						'red' => elgg_echo('golfscore:tee:red'),
					)
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-rating",
					'title' => elgg_echo('golfcourse:form:course_rating'),
					'placeholder' => elgg_echo('golfcourse:form:course_rating'),
					'name' => "blue_course_rating",
					'id' => "__course_rating",
					'value' => "$blue_course_rating",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-slope",
					'title' => elgg_echo('golfcourse:form:course_slope'),
					'placeholder' => elgg_echo('golfcourse:form:course_slope'),
					'name' => "blue_course_slope",
					'id' => "__course_slope",
					'value' => "$blue_course_slope",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-distance",
					'title' => elgg_echo('golfcourse:form:distance_total'),
					'placeholder' => elgg_echo('golfcourse:form:distance_total'),
					'name' => "blue_total",
					'id' => "__total",
					'value' => "$blue_total",
				)); ?>
			</td>
		</tr>
		<tr style="margin-top: 5px;" id="__tee_white">
			<td>
				<div id="__white_tee_color" class="elgg-golfscore-icon-tee-<?php echo $white_tee_name?>">&nbsp;</div>
				<label><?php echo elgg_echo('golfcourse:form:tee3'); ?></label>
				<?php echo elgg_view('input/dropdown', array(
					'class' => 'golfcourse-tee',
					'name' => 'white_tee_name', 
					'id' => '__tee_name',
					'value' => $white_tee_name,
					'options_values' => array(
						'gold' => elgg_echo('golfscore:tee:gold'),
						'black' => elgg_echo('golfscore:tee:black'),
						'blue' => elgg_echo('golfscore:tee:blue'),
						'white' => elgg_echo('golfscore:tee:white'),
						'red' => elgg_echo('golfscore:tee:red'),
					)
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-rating",
					'title' => elgg_echo('golfcourse:form:course_rating'),
					'placeholder' => elgg_echo('golfcourse:form:course_rating'),
					'name' => "white_course_rating",
					'id' => "__course_rating",
					'value' => "$white_course_rating",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-slope",
					'title' => elgg_echo('golfcourse:form:course_slope'),
					'placeholder' => elgg_echo('golfcourse:form:course_slope'),
					'name' => "white_course_slope",
					'id' => "__course_slope",
					'value' => "$white_course_slope",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-distance",
					'title' => elgg_echo('golfcourse:form:distance_total'),
					'placeholder' => elgg_echo('golfcourse:form:distance_total'),
					'name' => "white_total",
					'id' => "__total",
					'value' => "$white_total",
				)); ?>
			</td>
		</tr>
		<tr style="margin-top: 5px;" id="__tee_red">
			<td>
				<div id="__red_tee_color" class="elgg-golfscore-icon-tee-<?php echo $red_tee_name?>">&nbsp;</div>
				<label><?php echo elgg_echo('golfcourse:form:tee4'); ?></label>
				<?php echo elgg_view('input/dropdown', array(
					'class' => 'golfcourse-tee',
					'name' => 'red_tee_name', 
					'id' => '__tee_name',
					'value' => $red_tee_name,
					'options_values' => array(
						'gold' => elgg_echo('golfscore:tee:gold'),
						'black' => elgg_echo('golfscore:tee:black'),
						'blue' => elgg_echo('golfscore:tee:blue'),
						'white' => elgg_echo('golfscore:tee:white'),
						'red' => elgg_echo('golfscore:tee:red'),
					)
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-rating",
					'title' => elgg_echo('golfcourse:form:course_rating'),
					'placeholder' => elgg_echo('golfcourse:form:course_rating'),
					'name' => "red_course_rating",
					'id' => "__course_rating",
					'value' => "$red_course_rating",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-slope",
					'title' => elgg_echo('golfcourse:form:course_slope'),
					'placeholder' => elgg_echo('golfcourse:form:course_slope'),
					'name' => "red_course_slope",
					'id' => "__course_slope",
					'value' => "$red_course_slope",
				)); ?>
			</td>
			<td>
				<?php echo elgg_view('input/text', array(
					'class' => "golfcourse-distance",
					'title' => elgg_echo('golfcourse:form:distance_total'),
					'placeholder' => elgg_echo('golfcourse:form:distance_total'),
					'name' => "red_total",
					'id' => "__total",
					'value' => "$red_total",
				)); ?>
			</td>
		</tr>
	</tbody>
	</table>
	</div>
	<?php
		echo '<div style="margin-top: 5px;">';
		echo elgg_view('input/button', array(
				'value' => elgg_echo('golfscore:save'),
				'onclick' => 'onSaveCourseForm();',
				'class' => 'elgg-button-submit',
			));
		echo '</div>';
	?>
</div>
</div>
<script>
function onSaveCourseForm() {
	var golf_course_id = $('#__course_form').find('#__golf_course_id').val();
	var course_name = $('#__course_form').find('#__course_name').val();
	var par_total = $('#__course_form').find('#__par_total').val();
	var gold_tee_name = $('#__course_form').find('#__tee_name[name="gold_tee_name"]').val();
	var gold_course_rating = $('#__course_form').find('#__course_rating[name="gold_course_rating"]').val();
	var gold_course_slope = $('#__course_form').find('#__course_slope[name="gold_course_slope"]').val();
	var gold_total = $('#__course_form').find('#__total[name="gold_total"]').val();
	var blue_tee_name = $('#__course_form').find('#__tee_name[name="blue_tee_name"]').val();
	var blue_course_rating = $('#__course_form').find('#__course_rating[name="blue_course_rating"]').val();
	var blue_course_slope = $('#__course_form').find('#__course_slope[name="blue_course_slope"]').val();
	var blue_total = $('#__course_form').find('#__total[name="blue_total"]').val();
	var white_tee_name = $('#__course_form').find('#__tee_name[name="white_tee_name"]').val();
	var white_course_rating = $('#__course_form').find('#__course_rating[name="white_course_rating"]').val();
	var white_course_slope = $('#__course_form').find('#__course_slope[name="white_course_slope"]').val();
	var white_total = $('#__course_form').find('#__total[name="white_total"]').val();
	var red_tee_name = $('#__course_form').find('#__tee_name[name="red_tee_name"]').val();
	var red_course_rating = $('#__course_form').find('#__course_rating[name="red_course_rating"]').val();
	var red_course_slope = $('#__course_form').find('#__course_slope[name="red_course_slope"]').val();
	var red_total = $('#__course_form').find('#__total[name="red_total"]').val();
	onSaveGolfCourse(golf_course_id,course_name,par_total,
			gold_tee_name,gold_course_rating,gold_course_slope,gold_total,
			blue_tee_name,blue_course_rating,blue_course_slope,blue_total,
			white_tee_name,white_course_rating,white_course_slope,white_total,
			red_tee_name,red_course_rating,red_course_slope,red_total);
}
</script>
<style>
	table tbody tr td {
		padding-top: 2px;
		padding-left: 2px;
		vertical-align: middle;
	}
	.golfcourse-tee {
		width: 70px!important;
	}
	.golfcourse-rating {
		width: 60px;
	}
	.golfcourse-slope {
		width: 60px;
	}
	.golfcourse-distance {
		width: 70px;
	}
</style>